#
# qrouter Makefile
#

# Main compiler arguments
CFLAGS += @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = @DEFS@
STUB_DEFS = @stub_defs@
LIBS = @LIBS@
LDFLAGS += @LDFLAGS@
LDDL_FLAGS = @LDDL_FLAGS@
LD_RUN_PATH = @LD_RUN_PATH@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
LIB_SPECS_NOSTUB = @LIB_SPECS_NOSTUB@
LIB_SPECS = @LIB_SPECS@
INC_SPECS = @INC_SPECS@
TCL_LIB_DIR = @TCL_LIB_DIR@
TK_LIB_DIR = @TK_LIB_DIR@
EXTRA_LIB_SPECS = @EXTRA_LIB_SPECS@
INSTALL = @INSTALL@
SHDLIB_EXT = @SHDLIB_EXT@
EXEEXT = @EXEEXT@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
QROUTER_LIB_DIR = @QROUTER_LIB_DIR@
WISH_EXE = @WISH_EXE@
VERSION = @VERSION@
REVISION = @REVISION@
prefix = @prefix@
exec_prefix = @exec_prefix@

INSTALL_TARGET := @INSTALL_TARGET@
ALL_TARGET := @ALL_TARGET@

SOURCES = qrouter.c point.c maze.c mask.c node.c output.c qconfig.c lef.c def.c
OBJECTS := $(patsubst %.c,%.o,$(SOURCES))

SOURCES2 = graphics.c tclqrouter.c tkSimple.c delays.c antenna.c
OBJECTS2 := $(patsubst %.c,%.o,$(SOURCES2))

SOURCES3 = qrouterexec.c
OBJECTS3 := $(patsubst %.c,%.o,$(SOURCES3))

SOURCES4 = qrouternullg.c
OBJECTS4 := $(patsubst %.c,%.o,$(SOURCES4))

SOURCES5 = main.c
OBJECTS5 := $(patsubst %.c,%.o,$(SOURCES5))

BININSTALL = ${prefix}/bin
LIBINSTALL = ${prefix}/${QROUTER_LIB_DIR}
EXTRA_DEFS = -DQROUTER_PATH=\"${LIBINSTALL}\"

INSTALL_BININSTALL = @DIST_DIR@/bin
INSTALL_LIBINSTALL = @DIST_DIR@/${QROUTER_LIB_DIR}

all: $(ALL_TARGET)

install: $(INSTALL_TARGET)

nointerp: qrouter$(EXEEXT)

tcl: qrouter.sh qrouter.tcl qrouter$(SHDLIB_EXT) qrouterexec$(EXEEXT) \
	qrouternullg$(EXEEXT)

qrouter.tcl: qrouter.tcl.in
	sed -e '/LIBDIR/s#LIBDIR#${LIBINSTALL}#' \
	    -e '/VERSION/s#VERSION#${VERSION}#' \
	    -e '/REVISION/s#REVISION#${REVISION}#' \
		qrouter.tcl.in > $@

qrouter.sh: qrouter.sh.in
	sed -e '/WISH_EXE/s#WISH_EXE#${WISH_EXE}#' \
	    -e '/LIBDIR/s#LIBDIR#${LIBINSTALL}#' \
		qrouter.sh.in > $@
	chmod 0755 $@

qrouter$(EXEEXT): $(OBJECTS) $(OBJECTS5)
	$(CC) $(LDFLAGS) $(OBJECTS) $(OBJECTS5) -o $@ $(LIBS) -lm

qrouter$(SHDLIB_EXT): $(OBJECTS) $(OBJECTS2)
	$(RM) qrouter$(SHDLIB_EXT)
	$(CC) ${CFLAGS} ${STUB_DEFS} ${SHLIB_CFLAGS} -o $@ \
		${LDDL_FLAGS} $(OBJECTS) $(OBJECTS2) \
		${LDFLAGS} -lc ${LIBS} ${X_PRE_LIBS} -lX11 ${X_LIBS} \
		${X_EXTRA_LIBS} ${LIB_SPECS} ${EXTRA_LIB_SPECS} -lm

qrouterexec$(EXEEXT): $(OBJECTS3)
	$(RM) qrouterexec$(EXEEXT)
	$(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} ${EXTRA_DEFS} \
		${SOURCES3} ${INC_SPECS} -o $@  ${LIB_SPECS_NOSTUB} \
		${LD_RUN_PATH} ${LDFLAGS} ${X_PRE_LIBS} -lX11 ${X_LIBS} \
		${X_EXTRA_LIBS} ${LIBS} ${EXTRA_LIB_SPECS} -lm

qrouternullg$(EXEEXT): $(OBJECTS4)
	$(RM) qrouternullg$(EXEEXT)
	$(CC) ${CFLAGS} ${CPPFLAGS} ${DEFS} ${EXTRA_DEFS} \
		${SOURCES4} ${INC_SPECS} -o $@  ${LIB_SPECS_NOSTUB} \
		${LD_RUN_PATH} ${LDFLAGS} ${LIBS} ${EXTRA_LIB_SPECS} -lm

install-nointerp:
	@echo "Installing qrouter"
	$(INSTALL) -d $(DESTDIR)${INSTALL_BININSTALL}
	$(INSTALL) qrouter $(DESTDIR)${INSTALL_BININSTALL}

install-tcl: qrouter.sh qrouter.tcl qrouter$(SHDLIB_EXT) \
		qrouterexec$(EXEEXT) qrouternullg$(EXEEXT)
	@echo "Installing qrouter"
	$(INSTALL) -d $(DESTDIR)${INSTALL_BININSTALL}
	$(INSTALL) -d $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) qrouter.sh $(DESTDIR)${INSTALL_BININSTALL}/qrouter
	$(INSTALL) qrouter$(SHDLIB_EXT) $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) qrouterexec$(EXEEXT) $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) qrouternullg$(EXEEXT) $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) console.tcl $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) tkcon.tcl $(DESTDIR)${INSTALL_LIBINSTALL}
	$(INSTALL) qrouter.tcl $(DESTDIR)${INSTALL_LIBINSTALL}

uninstall:
	$(RM) $(DESTDIR)${INSTALL_BININSTALL}/qrouter

clean:
	$(RM) $(OBJECTS)
	$(RM) $(OBJECTS2)
	$(RM) $(OBJECTS3)
	$(RM) $(OBJECTS4)
	$(RM) $(OBJECTS5)
	$(RM) qrouterexec$(EXEEXT)
	$(RM) qrouternullg$(EXEEXT)
	$(RM) qrouter$(EXEEXT)
	$(RM) qrouter$(SHDLIB_EXT)
	$(RM) qrouter.tcl
	$(RM) qrouter.sh

veryclean:
	$(RM) $(OBJECTS)
	$(RM) $(OBJECTS2)
	$(RM) $(OBJECTS3)
	$(RM) $(OBJECTS4)
	$(RM) $(OBJECTS5)
	$(RM) qrouterexec$(EXEEXT)
	$(RM) qrouternullg$(EXEEXT)
	$(RM) qrouter$(EXEEXT)
	$(RM) qrouter$(SHDLIB_EXT)
	$(RM) qrouter.tcl
	$(RM) qrouter.sh

distclean:
	$(RM) $(OBJECTS)
	$(RM) $(OBJECTS2)
	$(RM) $(OBJECTS3)
	$(RM) $(OBJECTS4)
	$(RM) $(OBJECTS5)
	$(RM) qrouterexec$(EXEEXT)
	$(RM) qrouternullg$(EXEEXT)
	$(RM) qrouter$(EXEEXT)
	$(RM) qrouter$(SHDLIB_EXT)
	$(RM) qrouter.tcl
	$(RM) qrouter.sh

.c.o:
	$(CC) $(CFLAGS) $(CPPFLAGS) $(SHLIB_CFLAGS) $(DEFS) $(STUB_DEFS) \
		$(EXTRA_DEFS) $(INC_SPECS) -c $< -o $@
